<template>
  <div>
    <div>
      <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
        <el-form-item label="执行账户" prop="type">
          <el-radio-group v-model="formData.type" size="medium">
            <el-radio v-for="(item, index) in field102Options" :key="index" :label="item.value"
                      :disabled="item.disabled">{{ item.label }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item size="large" label="开始时间">
          <div class="block">
            <el-date-picker
              v-model="formData.start"
              value-format="timestamp"
              type="datetime"
              placeholder="选择开始时间">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item size="large" label="结束时间">
          <div class="block">
            <el-date-picker
              v-model="formData.end"
              value-format="timestamp"
              type="datetime"
              placeholder="选择结束时间">
            </el-date-picker>
          </div>
        </el-form-item>
        <el-form-item size="large">
          <el-button type="primary" @click="loadMxcKlineOrders">加载订单</el-button>
          <el-button type="primary" @click="reset">重置</el-button>
        </el-form-item>

      </el-form>
    </div>
    <el-table v-if="klineOrders.length>0"
              :data="klineOrders"
              v-loading="loading"
              height="700"
              border
              style="width: 100%">
      <el-table-column
        label="日期"
        prop="createTime"
        sortable
      >
        <template slot-scope="scope">{{ scope.row.createTime| dfmt }}</template>
      </el-table-column>
      <el-table-column
        prop="price"
        label="价格"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="quantity"
        label="数量"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="dealQuantity"
        label="已成交"
        sortable
      >
      </el-table-column>
      <el-table-column
        prop="dealType"
        sortable
        label="类型"
      >
        <template slot-scope="scope">
          {{ scope.row.type == 'BID' ? '买单' : '卖单' }}
        </template>
      </el-table-column>
    </el-table>
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[50, 100, 500, 1000]"
        :page-size="size"
        layout="total, sizes, prev, pager, next, jumper"
        :total="10000">
      </el-pagination>
    </div>
  </div>
</template>
<script>
import {
  getDealedOrder
} from "@/api/platform/running";

export default {
  components: {},
  props: {
    platform: null,
    runningId: null,
  },
  data() {
    return {
      currentPage: 1,
      size: 50,
      loading: false,
      klineOrders: [],
      formData: {
        type: 1,
        start: null,
        end: null,
      },
      rules: {
        type: [{
          required: true,
          message: '执行账户不能为空',
          trigger: 'change'
        }],
      },
      field102Options: [{
        "label": "深度账户",
        "value": 1
      }, {
        "label": "K线账户",
        "value": 2
      }],
    }
  },
  computed: {},
  watch: {},
  created() {
  },
  mounted() {
    // this.loadMxcKlineOrders()
  },
  methods: {
    loadMxcKlineOrders() {
      this.formData.size = this.size
      this.formData.page = this.currentPage
      this.formData.platform = this.platform
      this.klineOrders = []
      this.loading = true,
        getDealedOrder(this.runningId, this.formData).then(res => {
          this.klineOrders = res.data;
          this.loading = false
        }).catch(e => {
          this.loading = false
        })
    },

    reset() {
      this.formData = {
        type: 1,
        start: null,
        end: null,
      }
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.size = val
      this.loadMxcKlineOrders();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.currentPage = val
      this.loadMxcKlineOrders();
    }
  }
}

</script>
<style>
</style>
